package com.hanthink.web.controller.pc;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.system.domain.pc.EmImage;
import com.hanthink.system.service.pc.IEmImageService;
import com.hanthink.common.core.page.TableDataInfo;

/**
 * 设备文件Controller
 * 
 * @author hanthink
 * @date 2021-01-26
 */
@RestController
@RequestMapping("/equipment/image")
public class EmImageController extends BaseController
{
    @Autowired
    private IEmImageService emImageService;

    /**
     * 查询设备文件列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmImage emImage)
    {
        startPage();
        List<EmImage> list = emImageService.selectEmImageList(emImage);
        return getDataTable(list);
    }

    /**
     * 导出设备文件列表
     */
    @Log(title = "设备文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmImage emImage)
    {
        List<EmImage> list = emImageService.selectEmImageList(emImage);
        ExcelUtil<EmImage> util = new ExcelUtil<EmImage>(EmImage.class);
        return util.exportExcel(list, "image");
    }

    /**
     * 获取设备文件详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(emImageService.selectEmImageById(id));
    }

    /**
     * 新增设备文件
     */
    @PreAuthorize("@ss.hasPermi('equipment:image:add')")
    @Log(title = "设备文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmImage emImage)
    {
        return toAjax(emImageService.insertEmImage(emImage));
    }

    /**
     * 修改设备文件
     */
    @PreAuthorize("@ss.hasPermi('equipment:image:edit')")
    @Log(title = "设备文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmImage emImage)
    {
        return toAjax(emImageService.updateEmImage(emImage));
    }

    /**
     * 删除设备文件
     */
    @PreAuthorize("@ss.hasPermi('equipment:image:remove')")
    @Log(title = "设备文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emImageService.deleteEmImageByIds(ids));
    }
}
